import axios from '@/utils/request';
const baseUserURL = process.env.VUE_APP_USER_API;
const baseURL = process.env.VUE_APP_COMMON_API;
const baseDeviceURL = process.env.VUE_APP_DEVICE_API;
const baseMaintenanceURL = process.env.VUE_APP_MAINTENANCE_API;

//获取物模型
const getModelList = data => {
    return axios.get(baseDeviceURL + '/device/getModelList', {
        params: data
    });
};

//获取知识库的已有物模型
const getDeviceModelListByKnow = data => {
  return axios.get(baseMaintenanceURL + '/maintenance/getDeviceModelListByKnow', {
      params: data
  });
};

//获取知识库分类列表
const getKnowCategoryList = data => {
    return axios.get(baseMaintenanceURL + '/maintenance/getKnowCategoryList');
};

//新增知识库分类
const createKnowCategory = data => {
    return axios.post(baseMaintenanceURL + '/maintenance/createKnowCategory', data);
};

//修改知识库分类
const updateKnowCategory = data => {
    return axios.put(baseMaintenanceURL + '/maintenance/updateKnowCategory', data);
};

//删除知识库分类
const deleteKnowCategory = data => {
    return axios.delete(baseMaintenanceURL + '/maintenance/deleteKnowCategory', data);
};

//新增知识库
const createKnow = data => {
    return axios.post(baseMaintenanceURL + '/maintenance/createKnow', data);
};

//获取知识库列表
const getKnowList = data => {
    return axios.get(baseMaintenanceURL + '/maintenance/getKnowList', {
        params: data
    });
};

//修改知识库
const updateKnow = data => {
    return axios.put(baseMaintenanceURL + '/maintenance/updateKnow', data);
};

//删除知识库
const deleteKnow = data => {
    return axios.delete(baseMaintenanceURL + '/maintenance/deleteKnow', data);
};

// 上传文件
const uploadFile = data => {
    return axios.request({
        method: 'POST',
        url: baseURL + '/uploadFile',
        data,
        headers: {
            loadingText: encodeURI('上传中，请稍候...'),
            'Content-Type': 'multipart/form-data'
        }
    });
};

// 自定义请求方式
const demoPut = data => {
    return axios.request({
        method: 'PUT',
        url: baseUserURL + '/user/realNameAuthentication',
        data,
        headers: {
            hideLoading: true, //是否显示loading
            loadingText: encodeURI('实名认证中，请稍候...'), //loading加载文字
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
};

export {
    demoPut,
    getModelList,
    getDeviceModelListByKnow,
    getKnowCategoryList,
    createKnowCategory,
    updateKnowCategory,
    deleteKnowCategory,
    createKnow,
    uploadFile,
    getKnowList,
    deleteKnow,
    updateKnow
};
